<?php
include "../../db/dbConnect.php";
error_reporting(E_ALL && ~ E_NOTICE);

if($_SERVER['REQUEST_METHOD'] == 'GET' && $_GET['question']) {

    $sql = "select pq.idpr_question as question, pa.answer as answer, pa.idpr_answer as ida from u_profile_question as pq, u_profile_answer as pa
            where pq.idpr_question=pa.idquestion
                and idpr_question='" . $_GET['question'] . "'
                and pq.deleted=0
                ";
    $result=mysql_query($sql);
    if (mysql_error()) {
        echo mysql_error();exit();
    }

}
?>
<div class="hDetail w100p">

    <div class="w65p left">Thông tin câu hỏi:</div>
    <button id="edit" class="btn btn-small editBtn right" idu="">Chỉnh sửa</button>
</div>
<div class="questContent">
    <?php
        $query="select * from u_profile_question
                where idpr_question = '" . $_GET['question'] . "' and deleted=0 ";
    $re=mysql_query($query);
    $quest=mysql_fetch_array($re);
    echo '<div><textarea id="contQ" class="txtContQ" readonly >'.$quest["question"].'</textarea></div>';
    ?>
</div>
<div class="h w100p">Danh sách câu trả lời:</div>

<div class="lstAnswer">
    <ul>
        <?php
        while($row=mysql_fetch_array($result)){
            $idquest=$row['question'];
            $idans=$row['ida'];
            echo "<li class='block w100p answerList'><input type='text' ida='".$idans."' class='ansItem' value='".$row['answer']."' readonly /></li>";
        }
        ?>
    </ul>
</div>
<div class="hDetail w100p">
    <button id="update" class="btn btn-small updateBtn right hidden" idq="<?php echo $idquest ?>">Cập nhật</button>
</div>
<div class="clear"></div>
<script type="text/javascript">
    $("#edit").bind('click', function(e){
        e.preventDefault();
        $("#update").removeClass('hidden');
        $('input.ansItem').prop('readonly', false).addClass('inputActive');
        $("#contQ").prop('readonly', false).addClass('imputActive');
    });

    $("#update").bind('click', function(e){
        e.preventDefault();
        var id=$(this).attr('idq'),
            contQ=$("#contQ").val(),
            res='',
            page=$("#pag_nav").text();
        $(this).addClass('hidden');

        $(".ansItem").each(function(){
            $(this).prop('readonly', true).removeClass('inputActive');
            var ida=$(this).attr('ida'),
                cont=$(this).val();
            //alert(ida+'----'+cont);
            $.ajax({
                url:"web/admin/updateAnswer.php",
                type:"GET",
                data:"answer="+ida+"&content="+cont,
                success:function(re){
                    $("#detail").text(re);
                }
            })
        })

        $.ajax({
            url:"web/admin/updateQuestion.php",
            type:"GET",
            data:"question="+id+"&contentQuest="+contQ,
            success:function(re){
               // $("#detail").text(re);
                if(re!=1) alert(re);
            }
        })
        $("#tbList").load("web/admin/questionSearch.php?page="+page).fadeIn('slow');
        $("#loadDetail").load("web/admin/questionDetail.php?question="+id).fadeIn();
        $("#detail").hide().slideDown('fast').fadeOut(3000);
    });
</script>

